package frame1;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import event.MyWindowEventHandle;

public class Demo6 extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Demo6 frame = new Demo6();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Demo6() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel(new BorderLayout());
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		
		JDesktopPane desktop = new JDesktopPane();
		
		for(int i = 0; i < 3; i++){
			JInternalFrame internal = new JInternalFrame("窗体"+i, false, true, true);
			JPanel jpanel = new JPanel();
			jpanel.add(new JButton("按钮"));
			
			internal.setLocation(35 - i * 10, 35 - i * 10);
			internal.add(jpanel);
			internal.pack();
			internal.setVisible(true);
			
			
			desktop.add(internal);
		}
		
		//this.addWindowListener(new MyWindowEventHandle());
		
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.out.println("-------");
			}
		});
		
		desktop.setVisible(true);
		contentPane.add(desktop, BorderLayout.CENTER);
		setContentPane(contentPane);
	}

}
